Decimal to Hexadecimal
In [1]:
dec_num = 254
print('{:X}'.format(dec_num))
Note that I have used the format() function here together with the {:X} placeholder which tells Python to print the number as Hexadecimal.
There is a hex() function available but it prepends the output with "0x" which may be a nuisance for what you are doing.
HexHexadecimal to Decimal
In [2]:
hex_string = 'FE'
print(int(hex_string, 16))
Note the use of ", 16" in the int() function? That tells python that we are converting from a Hex string as opposed to an integer string.
The original of this file can be found at